package com.d0331;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;

public class AVGScore {
    static int id;
    static String name;
    static double[] score = new double[3];
    static double avg;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        try {
            for (int i = 0; i < 5; i++) {
                System.out.println("现在输入的是第" + (i + 1) + "名学生的信息");
                System.out.println("请输入学生ID");
                id = scanner.nextInt();
                System.out.println("请输入学生姓名");
                name = scanner.next();
                for (int j = 0; j < 3; j++) {
                    System.out.println("请输入学生第" + (j + 1) + "科成绩");
                    score[j] = scanner.nextDouble();
                }
                avg = (score[0] + score[1] + score[2]) / 3;
                System.out.println("同学" + name + "的平均分为" + avg);
                FileWriter fw = new FileWriter(new File("D:/student.txt"), true);
                fw.write("ID为" + id + "的学生" + name + "的\n第一科成绩为" + score[0] + "\n第二科成绩为" + score[1] + "\n第三科成绩为" + score[2] + "\n平均成绩为" + avg + "\n\n");
                fw.close();
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
